<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="12" :sm="8">
            <a-form-item label="指标名称" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
              <a-input placeholder="请输入指标名称" v-model="queryParam.indexName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8" :offset="4">
            <span style="float: right;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" >查询</a-button>
              <a-button type="primary" @click="searchResetBefore" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="!editDisabled">
      <a-button @click="handleAddScSituationIndexInfo" type="primary" icon="plus">新增</a-button>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="systemBatchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">取消勾选</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="dimensionInfoVoList" slot-scope="dimensionInfoVoList">
          <a-tag
            style="font-size: 14px; margin-top: 5px"
            v-for="(topic, index) in dimensionInfoVoList"
            :key="index"
            color="blue"
          >{{ topic.name }}</a-tag
          >
        </span>
        <span slot="isPercent" slot-scope="isPercent">
          {{ isPercent == 1 ? '是' : '否' }}
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleIndexEdit(record)" :disabled="editDisabled">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleViewData(record)">查看数据</a>
          <a-divider type="vertical" />
          <!-- <a @click="systemDel(record.id)" :disabled="editDisabled">删除</a> -->

          <a-popconfirm placement="topLeft" title="确定要删除此分类与该指标的关系数据吗?" @confirm="() => systemDel(record.id)">
            <a  :disabled="editDisabled">删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <select-sc-situation-index-info-modal-new  ref="modalForm" @ok="modalFormOk"/>
    <IndexData ref="indexData" />
  </a-card>
</template>

<script>
import { getAction, deleteAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SelectScSituationIndexInfoModalNew from './SelectScSituationIndexInfoModalNew'
import IndexData from './IndexData'
export default {
  name: 'SystemScSituationIndexInfoList',
  components: {
    SelectScSituationIndexInfoModalNew,
    IndexData
  },
  mixins: [JeecgListMixin, mixinDevice],
  props: {
    editDisabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      catalogId: null,
      description: '指标信息表管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '指标名称',
          align: 'center',
          dataIndex: 'indexName'
        },
        {
          title: '指标描述',
          align: 'center',
          dataIndex: 'indexDescription'
        },
        {
          title: '指标来源',
          align: 'center',
          dataIndex: 'indexOrigin_dictText'
        },
        {
          title: '目录提供方式',
          align: 'center',
          dataIndex: 'catalogDeliveryMode_dictText'
        },
        {
          title: '目录更新频率',
          align: 'center',
          dataIndex: 'catalogUpdateFrequency_dictText'
        },
        {
          title: '目录更新时间',
          align: 'center',
          dataIndex: 'catalogDataTime'
        },
        {
          title: '数据库名称',
          align: 'center',
          dataIndex: 'databaseName'
        },
        {
          title: '数据表名称',
          align: 'center',
          dataIndex: 'tableName'
        },
        {
          title: '数据同步时间',
          align: 'center',
          dataIndex: 'dataSyncTime'
        },
        {
          title: '数据更新频率',
          align: 'center',
          dataIndex: 'dataSyncFrequency_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 100,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/index/scSituationIndexDetail/queryByCatalogId',
        delete: '/index/scSituationIndexDetail/delete',
        deleteBatch: '/index/scSituationIndexDetail/deleteBatch',
        exportXlsUrl: '/index/scSituationIndexInfo/exportXls',
        importExcelUrl: 'index/scSituationIndexInfo/importExcel'

      },
      dictOptions: {},
      superFieldList: [],
      isorter: {
        column: null,
        order: null
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.getSuperFieldList()
  },
  methods: {
    handleIndexEdit(record) {
      record.catalogId = this.catalogId
      this.$refs.modalForm.edit(record)
    },
    handleViewData(record) {
      this.$refs.indexData.handleOpenData(record)
      // 查看数据
    },
    searchResetBefore() {
      this.queryParam = {
        catalogId: this.catalogId
      }
      this.loadData(1)
    },
    clearDataSource() {
      this.dataSource = []
      this.ipagination.total = 0
      this.ipagination.current = 1
      this.queryParam.catalogId = null
      this.catalogId = null
    },
    systemBatchDel() {
      var that = this
      this.$confirm({
        title: '确认删除',
        content: '确定要删除此分类与该指标的关系数据吗?',
        onOk: function() {
          var indexListStr = ''

          that.selectedRowKeys.forEach((item, index) => {
            if (index == 0) {
              indexListStr += item
            } else {
              indexListStr += ',' + item
            }
          })
          // { 'catalogId': that.catalogId, 'indexList': indexListStr }
          deleteAction(that.url.deleteBatch, { ids: indexListStr, catalogId: this.catalogId }).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
              that.onClearSelected()
            } else {
              that.$message.warning(res.message)
            }
          })
        }
      })
    },
    systemDel(val) {
      var that = this
      deleteAction(that.url.delete, { id: val, catalogId: this.catalogId }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
          that.onClearSelected()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    show(catalogId) {
      this.clearDataSource()
      if (catalogId === undefined || catalogId === null || catalogId === '') {
        //
      } else {
        this.catalogId = catalogId
        this.queryParam.catalogId = catalogId
        // this.searchResetBefore()
        this.loadData()
      }
    },
    initDictConfig() {
    },
    handleAddScSituationIndexInfo() {
      this.$refs.modalForm.add(this.catalogId)
    },
    getSuperFieldList() {
      const fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '指标名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dimensionInfoVoList', text: '维度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '描述', dictCode: '' })
      fieldList.push({ type: 'string', value: 'configId', text: '配置名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dataSource', text: '数据源', dictCode: 'sys_data_source,name,code' })
      fieldList.push({ type: 'string', value: 'tableName', text: '表名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tableColumn', text: '字段名', dictCode: '' })
      fieldList.push({ type: 'int', value: 'dataType', text: '数据类型', dictCode: 'column_data_type' })
      fieldList.push({ type: 'int', value: 'columnLength', text: '数据长度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'scale', text: '小数精度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'unit', text: '统计单位', dictCode: '' })
      fieldList.push({ type: 'int', value: 'isPercent', text: '是否率值', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'groupType', text: '汇聚类型', dictCode: 'index_group_type' })
      // fieldList.push({ type: 'int', value: 'status', text: '状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'updateBy', text: '编辑人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'updateTime', text: '编辑时间', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
